package com.zhou.framework.quartz.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zhou.framework.quartz.dto.QuartzLogQueryDto;
import com.zhou.util.NumberUtil;
import com.zhou.util.StringTool;
import com.zhou.framework.quartz.dao.QuartzLog;
import com.zhou.framework.quartz.mapper.QuartzLogMapper;
import com.zhou.framework.quartz.service.QuartzLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lang.zhou
 * @since 2023-02-21
 */
@Service
public class QuartzLogServiceImpl extends ServiceImpl<QuartzLogMapper, QuartzLog> implements QuartzLogService {

    @Override
    public void saveLog(QuartzLog log) {
        if(StringTool.isNotBlank(log.getLog()) && log.getLog().length() > 2000){
            log.setLog(StringTool.substring(log.getLog(),0,2000));
        }
        if(NumberUtil.upper0(log.getId())){
            updateById(log);
        }else{
            save(log);
        }
    }

    @Override
    public List<QuartzLog> listLog(QuartzLogQueryDto dto) {
        return baseMapper.listLog(dto);
    }
}
